package cruds.services;

import items.Service;

import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.AbstractReadOnlyModel;

import cruds.ParentList;
import dataproviders.ServiceDataProvider;
import dynamicmenus.ServicesMenu;
import home.Home;
import panels.BodyPanel;
import services.ServiceService;
import services.StockableService;
import staticmenus.StaticMenu;

@SuppressWarnings("serial")
public class ServiceList extends ParentList<Service>{

	public ServiceList(Home home) {
		super(home);
	}

	protected void modifyService(AjaxRequestTarget target, Service service) {
		CrudModifyService page = new CrudModifyService(this.getHome(),service);
		page.changePanel(target);
	}

	@Override
	protected void doUpdateAndRedirect(AjaxRequestTarget target,Item<Service> item) {
		this.modifyService(target, item.getModelObject());
	}

	@Override
	protected void doDeleteAndRedirect(AjaxRequestTarget target,Item<Service> item) {
		this.getService().delete(item.getModelObject());
		ServiceList listar = new ServiceList(this.getHome());
		listar.changePanel(target);
	}
	
	@Override
	protected void createFormFields(Item<Service> item) {
		item.add(new Label("name", item.getModelObject().getName()));
		item.add(new Label("price", String.valueOf(item.getModelObject().getSalePrice())));
	}

	@Override
	protected void initializeService() {
		this.setService(this.getHome().getGeneralService().getServiceSer());
	}

	@Override
	protected IDataProvider setDataProvider() {
		List<Service> services = this.getService().retriveAll();
		return new ServiceDataProvider(services);
	}

	@Override
	protected void updateDynamicMenu(AjaxRequestTarget target) {
		ServicesMenu menu = new ServicesMenu(this.getHome());
		menu.changePanel(target);
		
	}

	@Override
	protected void initializePanelTH(Form form) {
		form.add(new ServListTH());
		
	}

}
